package com.zhen.strategy.service.impl;


import com.alibaba.fastjson2.JSONObject;
import com.zhen.strategy.domain.PaymentContext;
import com.zhen.strategy.menu.BusiMenu;
import com.zhen.strategy.service.OrderService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.stereotype.Service;

import java.util.concurrent.ThreadLocalRandom;

@Service
@Slf4j
public class OrderServiceImpl implements OrderService {

    @Autowired
    private ApplicationContext applicationContext;

    @Override
    public void callOrder(PaymentContext context) {
        BusiMenu busiMenu = BusiMenu.getEnumByBusiType("order");
        String strategy = busiMenu.getStrategy();
        OrderStrategy orderStrategy = (OrderStrategy) applicationContext.getBean(strategy);
        orderStrategy.call(context);
    }

    @Override
    public String callOrder2(String para) {
        log.info("callOrder2方法执行了，入参是：{}", para);
        int nextInt = ThreadLocalRandom.current().nextInt(100);
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("key", nextInt);
        return jsonObject.toString();
    }


}
